<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoDB\BSON\Javascript class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb-bson-decimal128.unserialize.html">« MongoDB\BSON\Decimal128::unserialize</a></li>
      <li style="float: right;"><a href="mongodb-bson-javascript.construct.html">MongoDB\BSON\Javascript::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.bson.html">MongoDB\BSON</a></li>
    <li>The MongoDB\BSON\Javascript class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.mongodb-bson-javascript" class="reference">

 <h1 class="title">The MongoDB\BSON\Javascript class</h1>
 

 <div class="partintro"><p class="verinfo">(mongodb &gt;=1.0.0)</p>


  <div class="section" id="mongodb-bson-javascript.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    BSON type for Javascript code. An optional scope document may be specified
    that maps identifiers to values and defines the scope in which the code
    should be evaluated by the server.
   </p>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <span class="simpara">
     This BSON type is mainly used when executing database commands that take a
     Javascript function as a parameter, such as
     <a href="https://www.mongodb.com/docs/manual/reference/command/mapReduce/" class="link external">&raquo;&nbsp;mapReduce</a>.
    </span>
   </p></blockquote>
  </div>


  <div class="section" id="mongodb-bson-javascript.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="modifier">final</span>
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">MongoDB\BSON\Javascript</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.mongodb-bson-javascriptinterface.html" class="interfacename">MongoDB\BSON\JavascriptInterface</a></span><span class="oointerface">,  <a href="class.mongodb-bson-type.html" class="interfacename">MongoDB\BSON\Type</a></span><span class="oointerface">,  <a href="class.serializable.html" class="interfacename">Serializable</a></span><span class="oointerface">,  <a href="class.jsonserializable.html" class="interfacename">JsonSerializable</a></span><span class="oointerface">,  <a href="class.stringable.html" class="interfacename">Stringable</a></span> {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-javascript.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$code</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">object</span>|<span class="type">null</span></span> <code class="parameter">$scope</code><span class="initializer"> = <strong><code>null</code></strong></span></span>)</div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-javascript.getcode.html" class="methodname">getCode</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-javascript.getscope.html" class="methodname">getScope</a></span>(): <span class="type"><span class="type">?</span><span class="type">object</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-javascript.jsonserialize.html" class="methodname">jsonSerialize</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-javascript.serialize.html" class="methodname">serialize</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-javascript.tostring.html" class="methodname">__toString</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-javascript.unserialize.html" class="methodname">unserialize</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$serialized</code></span>): <span class="type"><span class="type void">void</span></span></div>

   }</div>


  </div>

  <div class="section">
   <h2 class="title">更新日志</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>PECL mongodb 1.12.0</td>
        <td>
         Implements <span class="interfacename"><a href="class.stringable.html" class="interfacename">Stringable</a></span> for PHP 8.0+.
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.3.0</td>
        <td>
         Implements <span class="interfacename"><a href="class.mongodb-bson-javascriptinterface.html" class="interfacename">MongoDB\BSON\JavascriptInterface</a></span>.
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.2.0</td>
        <td>
         Implements <span class="interfacename"><a href="class.serializable.html" class="interfacename">Serializable</a></span> and
         <span class="interfacename"><a href="class.jsonserializable.html" class="interfacename">JsonSerializable</a></span>.
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

 </div>

 







 






 






 






 






 






 







<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="mongodb-bson-javascript.construct.html">MongoDB\BSON\Javascript::__construct</a> — Construct a new Javascript</li><li><a href="mongodb-bson-javascript.getcode.html">MongoDB\BSON\Javascript::getCode</a> — Returns the Javascript's code</li><li><a href="mongodb-bson-javascript.getscope.html">MongoDB\BSON\Javascript::getScope</a> — Returns the Javascript's scope document</li><li><a href="mongodb-bson-javascript.jsonserialize.html">MongoDB\BSON\Javascript::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="mongodb-bson-javascript.serialize.html">MongoDB\BSON\Javascript::serialize</a> — Serialize a Javascript</li><li><a href="mongodb-bson-javascript.tostring.html">MongoDB\BSON\Javascript::__toString</a> — Returns the Javascript's code</li><li><a href="mongodb-bson-javascript.unserialize.html">MongoDB\BSON\Javascript::unserialize</a> — Unserialize a Javascript</li></ul>
</div>
</div></div></body></html>